package com.csst.business.action;



import java.io.IOException;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.csst.business.model.BUser;
import com.csst.business.model.TNews;
import com.csst.business.service.INewsService;
import com.csst.business.util.PageData;
import com.csst.business.util.PaginationUtil;
import com.csst.popular.bean.User;
import com.csst.popular.bean.message.NewsMessage.News;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class NewsAction extends ActionSupport{
	private INewsService newsService;
	private TNews news;
	private List<TNews> newsList;
	//分页参数
	private PageData pageData;
	private int pagesize=10;
	private  int currentPage = 1;
	public String testAction(){
		return SUCCESS;
	}
	
	public String test(){
		//newsService.saveDate(news);
		return "aaa";
	}
	
	//取得新闻列表
	public String getNewslist(){
		HttpServletRequest request = ServletActionContext.getRequest();
		System.out.println(request.getSession().getAttribute("userOpenId")+"==099");
		int totle = newsService.getOrderTotle();
		pageData= PaginationUtil.getPageData(pagesize,totle, currentPage);
		newsList =  newsService.getAllOnlineList(pageData.getStartNum(),pageData.getEndNum());
		return "newslist";
	}
	//取得新闻列表
	public String getWNewslist(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String openId = (String) request.getSession().getAttribute("openId");
		if(openId==null){
			openId = (String)request.getParameter("openId");
			request.getSession().setAttribute("openId", openId);
		}
		int totle = newsService.getOrderTotle();
		pageData= PaginationUtil.getPageData(pagesize,totle, currentPage);
		newsList =  newsService.getAllOnlineList(pageData.getStartNum(),pageData.getEndNum());
		return "wnewslist";
	}
	//新增保存
	public String saveNews(){
		news.setSCreatetime(new Date());
		news.setSCreatuer("管理员");
		news.setSState(1);
		newsService.saveDate(news);
		return "news";
	}
	//修改
	public String updateNews(){
		newsService.updateDate(news);
		return "news";
	}
	//根据id查找对象
	public String getNewsById(){
		news = newsService.getNewsById(news.getId());
		return "updatepre";
	}
	//根据id查找对象
	public String getWNewsById(){
		news = newsService.getNewsById(news.getId());
		return "wupdatepre";
	}
	
	//删除订单
	public boolean deleteNewsAjax(String id){
		return newsService.deleteNewsById(id);
	}
	public INewsService getNewsService() {
		return newsService;
	}

	public void setNewsService(INewsService newsService) {
		this.newsService = newsService;
	}

	public TNews getNews() {
		return news;
	}

	public void setNews(TNews news) {
		this.news = news;
	}

	public List<TNews> getNewsList() {
		return newsList;
	}

	public void setNewsList(List<TNews> newsList) {
		this.newsList = newsList;
	}

	public PageData getPageData() {
		return pageData;
	}

	public void setPageData(PageData pageData) {
		this.pageData = pageData;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	
}
